package lzzy.demo.service;

import lzzy.demo.entity.Comment;
import lzzy.demo.repository.CommentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class CommentService {
    @Autowired
    CommentRepository commentRepository;
        public void  SelectCommentById(Integer id){
            Optional<Comment> comment=commentRepository.findById(id);
            if(comment.isPresent())
                System.out.println(comment.get());
            else
                System.out.println("没找到");
        }
        public List<Comment> SelectAllStortByAId(){
            return  commentRepository.findAll(Sort.by(Sort.Direction.ASC, "aId"));
        }

}
